package com.cjg.xiancheng;
//多线程操作同一个资源，线程混乱 资源冲突

//继承runnable
public class threadTest3  implements  Runnable{
    //模拟抢票
    private int ticket;
    public threadTest3(int ticket){
        this.ticket=ticket;
    }

    //重写run方法
    @Override
    public void run() {

        while(true){
            if (ticket<=0){
                break;
            }
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"获得第"+ticket--+"'票");
        }
    }

    public static void main(String[] args) {
        // new  Thread 。start方法调用
        threadTest3 threadTest3 = new threadTest3(5);
        new Thread(threadTest3,"姓名").start();new Thread(threadTest3,"座号").start();new Thread(threadTest3,"班级").start();
    }



}
